var exec=require('child_process').exec;
var querystring = require("querystring");

var chatRoom=require('./chatRoom');

function responseWrite(response,message){
	response.writeHead(200, {"Content-Type": "text/html"});
	response.write(message);
	response.end();
}

function login(request,response){
	var body = '<html>'
		+    '<head>'
		+    '<meta http-equiv="Content-Type" '
		+    'content="text/html; charset=UTF-8" />'
		+    '</head>'
		+    '<body>'
		+    '<form action="/upload" enctype="multipart/form-data" '
		+    'method="post">'
		+    '<input type="file" name="upload">'
		+    '<input type="submit" value="Upload file" />'
		+    '</form>'
		+    '</body>'
		+    '</html>';
	responseWrite(response,body);
}
function registe(request,response){
	console.log('Registe success!');
	console.log(response);
	responseWrite(response,'registe');
}
function upload(request,response){
	console.log('Upload success!');
	var content=querystring.parse(postData).text;
	if(typeof content!='string'){
		content='';
	}
	responseWrite(response,content);
}

function chat(request,response){
	
	console.log('Upload success!');
	var content=querystring.parse(postData).text;
	if(typeof content!='string'){
		content='';
	}
	responseWrite(response,content);
}
function enterRoom(request,response){
	chatRoom.enterRoom(request,response);
}
function dispatcherMessage(request,response){
	chatRoom.dispatcherMessage(request,response);
}
function getPersonsInfo(request,response){
	chatRoom.getPersonsInfo(request,response);
}
function comnetPersonsInfo(request,response){
	chatRoom.comnetPersonsInfo(request,response);
}
function activateOnline(request,response){
	chatRoom.activateOnline(request,response);
}
function comnetMessageInfo(request,response){
	chatRoom.comnetMessageInfo(request,response);
}
function sendMessage(request,response){
	chatRoom.sendMessage(request,response);
}

exports.login=login;
exports.registe=registe;
exports.upload=upload;
exports.chat=chat;
exports.enterRoom=enterRoom;
exports.comnetPersonsInfo=comnetPersonsInfo;
exports.activateOnline=activateOnline;
exports.comnetMessageInfo=comnetMessageInfo;
exports.sendMessage=sendMessage;